var throttle = function(func, wait, { leading = true } = {}) {
  var lastArgs;
  var lastThis;
  var lastCallTime = 0;
  var isLeadingInvoked = false;
  return function(...arg) {
    lastThis = this;
    lastArgs = arg;
    if (!lastCallTime){
        lastCallTime =  Date.now();
    }
    if (Date.now() - lastCallTime >= wait) {
      func.apply(lastThis, lastArgs);
      lastCallTime = Date.now();
    } else if (!isLeadingInvoked && leading) {
        func.apply(lastThis, lastArgs);
        isLeadingInvoked = true;
        lastCallTime = Date.now();
    }
  };
};